package cn.moukou.dictator.util;

import cn.moukou.dictator.pojo.Activity;
import org.neo4j.ogm.typeconversion.CompositeAttributeConverter;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActivityConverter implements CompositeAttributeConverter<Activity> {
    @Override
    public Map<String, ?> toGraphProperties(Activity entity) {
        Map<String, Object> properties = new HashMap<>();
        if (entity != null)  {
            properties.put("activity_name", entity.getName());
            properties.put("activity_time", entity.getTimestamp());
            properties.put("activity_description", entity.getDescription());
        }
        return properties;
    }

    @Override
    public Activity toEntityAttribute(Map<String, ?> map) {
        if(!map.get("node_type").toString().equals("activity")) {
            return null;
        }
        Activity entity = new Activity();
        entity.setName((String) map.get("activity_name"));
        entity.setDescription((String) map.get("activity_description"));

        return entity;
    }
}
